package com.aikon.wht.designPattern.consumer;

/**
 * @author haitao.wang http://www.bestwonderful.com
 */
public class Producer extends AbstractRunner {


    public Producer(String name, Object lock, Product product) {
        super(name, lock, product);
    }

    public void produce() throws InterruptedException {

        System.out.println(Thread.currentThread().getName() + " begin");
        synchronized (lock) {
            while (!product.isEmpty()) {
                System.out.println(Thread.currentThread().getName() + " Wait");
                lock.wait();
            }
            product.produce(Thread.currentThread().getName());
            System.out.println(Thread.currentThread().getName() + " produce");
            lock.notifyAll();
        }


    }

    @Override
    protected void execute() throws InterruptedException {
//        while (true)
            this.produce();
    }
}
